/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedbean.TX.tta;

import Helper.TTAHelper.Helper_CustomerLoyalty;
import Helper.TTAHelper.Helper_CustomerValue;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import managedbean.TX.CustomerIOTRPortal.FakeMainPortalMB;
import session.TX.CustomerAnalysisSBRemote;

/**
 *
 * @author Lu Xiaodi
 */
@ManagedBean(name = "stakeholderCustAnalysisMB")
@ViewScoped
public class StakeholderCustAnalysisMB {

    @EJB
    CustomerAnalysisSBRemote analysisBean;
    @ManagedProperty(value = "#{fakeMainPortalMB}")
    private FakeMainPortalMB portalManagedBean;
    private Double discountRate = new Double(0.15);
    private Double expPerRes = new Double(100);
    private Double avgExp_CustValue = new Double(100);

    /** Creates a new instance of OutletCustAnalysisMB */
    public StakeholderCustAnalysisMB() {
    }

    public Double getCLV() {
        String stakeholderName = portalManagedBean.getStakeholderName();
        if (stakeholderName == null) {
            return null;
        } else {
            if (discountRate != null && expPerRes != null) {
                return analysisBean.calculateGC(stakeholderName, discountRate, expPerRes);
            } else {
                return null;
            }
        }

    }

    public List<Helper_CustomerLoyalty> getSortedLocalLoyaltyIdx() {
        String sName = portalManagedBean.getStakeholderName();
        if (sName == null) {
            return null;
        }
        return analysisBean.getSortedLocalLoyaltyIdx(sName);
    }

    public List<Helper_CustomerLoyalty> getSortedForeignLoyaltyIdx() {
        String sName = portalManagedBean.getStakeholderName();
        if (sName == null) {
            return null;
        }
        return analysisBean.getSortedForeignLoyaltyIdx(sName);
    }

    public List<Helper_CustomerValue> getSortedLocalCustValue() {
        String sName = portalManagedBean.getStakeholderName();
        if (sName == null) {
            return null;
        }
        List<Helper_CustomerValue> returnList = analysisBean.getSortedLocalCustValue(sName, avgExp_CustValue);
        for (int i = 0; i < returnList.size(); i++) {
            returnList.get(i).setRank(i + 1);
        }
        return returnList;
    }

    public List<Helper_CustomerValue> getSortedForeignCustValue() {
        String sName = portalManagedBean.getStakeholderName();
        if (sName == null) {
            return null;
        }
        List<Helper_CustomerValue> returnList = analysisBean.getSortedForeignCustValue(sName, avgExp_CustValue);
        for (int i = 0; i < returnList.size(); i++) {
            returnList.get(i).setRank(i + 1);
        }
        return returnList;
    }

    public FakeMainPortalMB getPortalManagedBean() {
        return portalManagedBean;
    }

    public void setPortalManagedBean(FakeMainPortalMB portalManagedBean) {
        this.portalManagedBean = portalManagedBean;
    }

    public Double getDiscountRate() {
        return discountRate;
    }

    public void setDiscountRate(Double discountRate) {
        this.discountRate = discountRate;
    }

    public Double getExpPerRes() {
        return expPerRes;
    }

    public void setExpPerRes(Double expPerRes) {
        this.expPerRes = expPerRes;
    }

    public Double getAvgExp_CustValue() {
        return avgExp_CustValue;
    }

    public void setAvgExp_CustValue(Double avgExp_CustValue) {
        this.avgExp_CustValue = avgExp_CustValue;
    }
    
}
